package com.mall.coupon.server.controller;

import com.github.pagehelper.PageInfo;
import com.mall.common.core.domain.Result;
import com.mall.common.core.web.controller.BaseController;
import com.mall.coupon.common.domain.CmsSkuCouponMiddle;
import com.mall.coupon.server.service.CmsCouponService;
import com.mall.coupon.common.domain.CmsCoupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("cmsCoupon")
@CrossOrigin
public class CmsCouponController extends BaseController {
    @Autowired
    private CmsCouponService cmsCouponService;

    @GetMapping("/list")
    public Result listCoupon(CmsCoupon cmsCoupon)
    {
        List<CmsCoupon> cmsCouponPageInfo = cmsCouponService.listCoupon(cmsCoupon);
        return getDataTable(cmsCouponPageInfo);
    }

    @GetMapping("/findBySkuId/{skuId}")
    public Result<List<CmsSkuCouponMiddle>> findBySkuId(@PathVariable Long skuId){
        List<CmsSkuCouponMiddle> bySkuId = cmsCouponService.findBySkuId(skuId);
        return Result.success(bySkuId);
    }

    @GetMapping("/findByCoupon")
    public Result<List<CmsCoupon>> findByCoupon(){
        List<CmsCoupon> byCoupon = cmsCouponService.findByCoupon();
        return Result.success(byCoupon);
    }




}
